package com.aigou.admin.service.impl;

import com.aigou.admin.dao.Shop_Cart_ProductDao;
import com.aigou.admin.dao.impl.Shop_Cart_ProductDaoImpl;
import com.aigou.admin.entity.PageEntity;
import com.aigou.admin.entity.Shop_Cart_Product;
import com.aigou.admin.service.Shop_Cart_ProductService;

import java.util.List;

public class Shop_Cart_ProductServiceImpl implements Shop_Cart_ProductService {
    private Shop_Cart_ProductDao cartProductDao = new Shop_Cart_ProductDaoImpl();

    @Override
    public Boolean save(Shop_Cart_Product shopCartProduct) {
        return cartProductDao.insert(shopCartProduct);
    }

    @Override
    public Boolean update(Shop_Cart_Product shopCartProduct) {
        return cartProductDao.update(shopCartProduct);
    }

    @Override
    public Boolean remove(String id) {
        return cartProductDao.delete(id);
    }

    @Override
    public List<Shop_Cart_Product> selectAll() {
        return cartProductDao.selectAll();
    }

    @Override
    public PageEntity<Shop_Cart_Product> findPage(Integer current, Integer pageSize) {
        //总条数
        Integer total = cartProductDao.selectCount();
        //分页查所有
        List<Shop_Cart_Product> cart_products = cartProductDao.selectLimit((current-1)*pageSize,pageSize);
        //响应数据
        PageEntity<Shop_Cart_Product> pageEntity = new PageEntity<>();
        pageEntity.setCurrent(current);
        pageEntity.setPageSize(pageSize);
        pageEntity.setRecords(cart_products);
        pageEntity.setTotal(total);
        return pageEntity;
    }
}
